var t, e = (t = require("@vant/weapp/toast/toast")) && t.__esModule ? t : {
    default: t
};

require("../../utils/config");

var i = require("../../utils/request"), a = require("../../utils/api"), o = require("../../utils/storage"), n = require("../../utils/map-convert");

Component({
    properties: {
        city: {
            type: String,
            value: ""
        }
    },
    data: {
        scrolly: !0,
        curindex: 0,
        list: [],
        indexList: [],
        city: "",
        inputVal: "",
        hidden: !0,
        toViewid: "",
        themeColor: getApp().globalData.themeColor,
        btnLoading: !1
    },
    lifetimes: {
        attached: function() {
            this.selectWcaCityAll();
        },
        detached: function() {},
        ready: function() {}
    },
    methods: {
        jumpTo: function(t) {
            this.setData({
                toViewid: t.currentTarget.dataset.myid,
                curindex: t.currentTarget.dataset.idx
            });
        },
        choose: function(t) {
            this.triggerEvent("change", t.currentTarget.dataset.item), o.setStorageSync(o.storageKey.cityInfo, {
                city: t.currentTarget.dataset.item.name,
                cityCode: t.currentTarget.dataset.item.code
            });
        },
        selectWcaCityAll: function() {
            var t = this;
            i.request(i.HttpMethod.GET, a.apiRoute.selectWcaCityAll, {}).then(function(e) {
                "20000" == e.code && t.setData({
                    indexList: e.data.initialCityList,
                    list: e.data.wcaCityDtoList
                });
            });
        },
        getLoc: function() {
            var t = this;
            t.setData({
                btnLoading: !0
            }), setTimeout(function() {
                t.setData({
                    btnLoading: !1
                });
            }, 5e3), wx.getLocation({
                type: "gcj02",
                success: function(e) {
                    var i = n.qqMapToBMap(e.longitude, e.latitude);
                    t.setData({
                        latitude: i[1],
                        longitude: i[0]
                    }), o.setStorageSync(o.storageKey.locationInfo, {
                        expireTimestamp: new Date().getTime() + 6e5,
                        latitude: i[1].toString(),
                        longitude: i[0].toString()
                    }), t.selectCityByCoordinates(i[1].toString(), i[0].toString());
                },
                fail: function(t) {
                    console.log("微信获取位置信息失败：" + t.errMsg), t.errMsg.indexOf("频繁") > -1 ? (0, e.default)({
                        message: "请勿频繁定位",
                        duration: 1e3
                    }) : wx.showModal({
                        title: "提示",
                        content: "如果您想要显示推荐机构，可点击小程序右上角“···”，设置中允许使用位置信息，并重新进入小程序",
                        showCancel: !1
                    });
                }
            });
        },
        selectCityByCoordinates: function(t, n) {
            var r = this, s = a.apiRoute.selectCityByCoordinates + "?latitude=" + t + "&longitude=" + n;
            i.request(i.HttpMethod.GET, s, {}).then(function(s) {
                if (s.success) {
                    var c = s.data.filter(function(t) {
                        return "1" == t.deep;
                    });
                    if (null != c && null != c && c.length > 0) {
                        var u = c[0].id + "00", d = c[0].name;
                        r.setData({
                            city: d,
                            cityCode: u
                        }), o.setStorageSync(o.storageKey.cityInfo, {
                            city: d,
                            cityCode: u
                        });
                        var l = a.apiRoute.selectWcaInstitutionByCityCode + "?cityCode=" + u + "&latitude=" + t + "&longitude=" + n;
                        i.request(i.HttpMethod.GET, l, {}).then(function(t) {
                            if ("20000" == t.code) {
                                var e = !1;
                                t.data.forEach(function(t) {
                                    t.cityCode == u && (e = !0);
                                }), 0 == e ? wx.showModal({
                                    title: "提示",
                                    content: "您所在城市暂无开业机构，请手动切换选择城市",
                                    showCancel: !1
                                }) : r.triggerEvent("change", {
                                    code: u,
                                    name: d
                                });
                            }
                        });
                    }
                } else o.setStorageSync(o.storageKey.cityInfo, {
                    city: "",
                    cityCode: ""
                }), (0, e.default)({
                    message: "获取城市信息失败",
                    duration: 5e3
                });
            });
        }
    }
});